import 'package:flutter/material.dart';

import 'xlcolors.dart';
import 'xlsize.dart';

/// 阴影
List<BoxShadow> BaseBoxShadow({
  Color? color,
  double? blurRadius,
  double? spreadRadius,
  Offset? offset,
}) {
  return [
    BoxShadow(
      color: color ?? const Color.fromARGB(18, 0, 0, 0),
      blurRadius: blurRadius ?? 10,
      spreadRadius: spreadRadius ?? 2,
      offset: offset ?? const Offset(2, 2), // 阴影偏移量
    ),
  ];
}

/// 装饰器 基础样式 只可设置颜色，和圆角
BoxDecoration BaseBoxDecoration(
    {Color? color = Colors.white, double? borderRadius}) {
  return BoxDecoration(
    color: color,
    borderRadius: BorderRadius.circular(borderRadius ?? 10.0), // 设置圆角半径为10
  );
}

/// 装饰器 样式 颜色、圆角、阴影
BoxDecoration BaseBoxDecorationShadow({
  Color? color = Colors.white,
  Color? shadowColor,
  double? borderRadius,
  double? blurRadius,
  double? spreadRadius,
  Offset? offset,
}) {
  return BoxDecoration(
    color: color,
    borderRadius: BorderRadius.circular(borderRadius ?? 10.0), // 设置圆角半径为10
    boxShadow: BaseBoxShadow(
      color: shadowColor,
      blurRadius: blurRadius,
      spreadRadius: spreadRadius,
      offset: offset,
    ),
  );
}

///上部圆角装饰器
BoxDecoration BaseBoxDecorationTop(
    {Color? color = Colors.white, double? borderRadius = 8}) {
  return BoxDecoration(
    color: color,
    borderRadius: BorderRadius.only(
        topLeft: Radius.circular(borderRadius ?? 10.0),
        topRight: Radius.circular(borderRadius ?? 10.0)),
  );
}

/// 水平分割线
Widget DividerDefault({Color? color}) {
  return Divider(
    color: color ?? XlColors.dividerColor,
    height: 0.5,
  );
}

/// 垂直分割线
Widget DividerVerticalDefault({Color? color}) {
  return Divider(
    color: color ?? XlColors.dividerColor,
    height: 0.5,
  );
}

/// 水平间隔
Widget IntervalSpace({double? height, Color? color}) {
  return Divider(
    height: height ?? 10,
    color: color ?? Colors.transparent,
  );
}

/// Button 封装
Widget BaseButtonText(
  String text, {
  double? width,
  double? height = 44,
  double? fontSize,
  FontWeight? fontWeight,
  EdgeInsetsGeometry? margin,
  VoidCallback? onPressed,
  Color? textColor,
  Color? borderColor,
  double? borderWidth, // 边框宽度
  Color? bgColor,
  double? radius, // 圆角尺寸
}) {
  return Container(
    height: height,
    width: width,
    margin: margin,
    child: OutlinedButton(
      onPressed: onPressed,
      child: Text(
        text,
        style: TextStyle(
            color: textColor ?? XlColors.color1890,
            fontSize: fontSize ?? XlSize.textDefault,
            fontWeight: fontWeight ?? FontWeight.w400),
      ),
      style: ButtonStyle(
        backgroundColor: MaterialStateProperty.all(bgColor ?? Colors.white),
        padding: MaterialStateProperty.all(EdgeInsets.zero),

        ///设置按钮边框颜色和宽度
        side: MaterialStateProperty.all(BorderSide(
            color: borderColor ?? XlColors.color1890,
            width: borderWidth ?? 0.8)),

        ///设置按钮圆角
        shape: MaterialStateProperty.all(RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(radius ?? 22.5))),

        ///去掉点击时的涟漪效果
        overlayColor: MaterialStateProperty.all(Colors.transparent),
      ),
    ),
  );
}

/// 蓝色边框文本按钮
Widget ButtonTextBlueBorder(
  String text, {
  EdgeInsetsGeometry? margin,
  VoidCallback? onPressed,
}) {
  return BaseButtonText(
    text,
    margin: margin,
    onPressed: onPressed,
    radius: 10,
  );
}

/// 蓝色背景文本按钮
Widget ButtonTextBlueBg(
  String text, {
  EdgeInsetsGeometry? margin,
  VoidCallback? onPressed,
}) {
  return BaseButtonText(
    text,
    margin: margin,
    onPressed: onPressed,
    textColor: Colors.white,
    bgColor: XlColors.color1890,
    radius: 10,
  );
}

//加号按钮
Widget addButton({
  EdgeInsetsGeometry? margin,
  VoidCallback? onPressed,
}) {
  return Container(
      height: 36,
      width: double.infinity,
      margin: margin,
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(8.0), color: XlColors.bgDDEEFF),
      child: IconButton(
        icon: Image.asset('assets/images/ic_add.png'),
        onPressed: onPressed,
      ));
}

//带下拉输入框样式
InputDecoration dropDownInputDecoration({
  String? hint,
  Color? fillColor = XlColors.bgBodyGray,
  TextStyle? hintStyle = const TextStyle(color: XlColors.color65),
}) {
  return InputDecoration(
      filled: true,
      enabledBorder: const OutlineInputBorder(
          borderRadius: BorderRadius.all(Radius.circular(4)),
          borderSide: BorderSide(color: XlColors.borderD5D4D4, width: 1)),
      focusedBorder: const OutlineInputBorder(
          borderRadius: BorderRadius.all(Radius.circular(4)),
          borderSide: BorderSide(color: XlColors.borderD5D4D4, width: 1)),
      disabledBorder: const OutlineInputBorder(
          borderRadius: BorderRadius.all(Radius.circular(4)),
          borderSide: BorderSide(color: XlColors.borderD5D4D4, width: 1)),
      hintText: hint,
      fillColor: fillColor,
      contentPadding: const EdgeInsets.fromLTRB(8, 0, 10, 0),
      hintStyle: hintStyle,
      suffixIcon:
          const ImageIcon(AssetImage("assets/images/ic_call_on_down.png")),
      suffixIconConstraints: const BoxConstraints(minWidth: 20, maxHeight: 10));
}

//灰色输入框样式
InputDecoration greyBorderInputDecoration(
    {String? hint, Color fillColor = Colors.white}) {
  return InputDecoration(
      filled: true,
      enabledBorder: const OutlineInputBorder(
          borderRadius: BorderRadius.all(Radius.circular(4)),
          borderSide: BorderSide(color: XlColors.colorEEEEEE, width: 1)),
      focusedBorder: const OutlineInputBorder(
          borderRadius: BorderRadius.all(Radius.circular(4)),
          borderSide: BorderSide(color: XlColors.colorEEEEEE, width: 1)),
      disabledBorder: const OutlineInputBorder(
          borderRadius: BorderRadius.all(Radius.circular(4)),
          borderSide: BorderSide(color: XlColors.colorEEEEEE, width: 1)),
      hintText: hint,
      fillColor: fillColor,
      contentPadding: const EdgeInsets.fromLTRB(8, 0, 10, 0),
      hintStyle: const TextStyle(color: XlColors.color25));
}

InputDecoration greyBackInputDecoration(
    {String? hint, Color fillColor = Colors.white}) {
  return InputDecoration(
      filled: true,
      enabledBorder: const OutlineInputBorder(
          borderRadius: BorderRadius.all(Radius.circular(4)),
          borderSide: BorderSide(color: XlColors.bgF3F3F3, width: 1)),
      focusedBorder: const OutlineInputBorder(
          borderRadius: BorderRadius.all(Radius.circular(4)),
          borderSide: BorderSide(color: XlColors.bgF3F3F3, width: 1)),
      disabledBorder: const OutlineInputBorder(
          borderRadius: BorderRadius.all(Radius.circular(4)),
          borderSide: BorderSide(color: XlColors.bgF3F3F3, width: 1)),
      hintText: hint,
      fillColor: XlColors.bgF3F3F3,
      contentPadding: const EdgeInsets.fromLTRB(8, 0, 10, 0),
      hintStyle: const TextStyle(color: XlColors.color25));
}
